#!/usr/bin/env bash
set -ex

cd $(dirname $0)/..

source ./scripts/version.sh

./scripts/build-image-runtime

awk '{print $1}' << EOF > build/images-core.txt
    ${REGISTRY}/${REPO}/${PROG}-runtime:${DOCKERIZED_VERSION}
EOF

xargs -n1 -t docker image pull --quiet << EOF >> build/images-core.txt
    ${REGISTRY}/rancher/hardened-kubernetes:${KUBERNETES_IMAGE_TAG}
    ${REGISTRY}/rancher/hardened-coredns:v1.8.5-build20211119
    ${REGISTRY}/rancher/hardened-cluster-autoscaler:v1.8.5-build20211119
    ${REGISTRY}/rancher/hardened-dns-node-cache:1.21.2-build20211119
    ${REGISTRY}/rancher/hardened-etcd:${ETCD_VERSION}-build20211118
    ${REGISTRY}/rancher/hardened-k8s-metrics-server:v0.5.0-build20211119
    ${REGISTRY}/rancher/klipper-helm:v0.6.7-build20211110
    ${REGISTRY}/rancher/pause:${PAUSE_VERSION}
    ${REGISTRY}/rancher/mirrored-ingress-nginx-kube-webhook-certgen:v1.0
    ${REGISTRY}/rancher/nginx-ingress-controller:nginx-1.0.2-hardened2
    ${REGISTRY}/rancher/rke2-cloud-provider:${CCM_VERSION}
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-canal.txt
    ${REGISTRY}/rancher/hardened-calico:v3.20.2-build20211119
    ${REGISTRY}/rancher/hardened-flannel:v0.15.1-build20211119
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-cilium.txt
    ${REGISTRY}/rancher/mirrored-cilium-cilium:v1.10.4
    ${REGISTRY}/rancher/mirrored-cilium-operator-aws:v1.10.4
    ${REGISTRY}/rancher/mirrored-cilium-operator-azure:v1.10.4
    ${REGISTRY}/rancher/mirrored-cilium-operator-generic:v1.10.4
    ${REGISTRY}/rancher/mirrored-cilium-startup-script:62bfbe88c17778aad7bef9fa57ff9e2d4a9ba0d8
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-calico.txt
    ${REGISTRY}/rancher/mirrored-calico-operator:v1.20.4
    ${REGISTRY}/rancher/mirrored-calico-ctl:v3.20.2
    ${REGISTRY}/rancher/mirrored-calico-kube-controllers:v3.20.2
    ${REGISTRY}/rancher/mirrored-calico-typha:v3.20.2
    ${REGISTRY}/rancher/mirrored-calico-node:v3.20.2
    ${REGISTRY}/rancher/mirrored-calico-pod2daemon-flexvol:v3.20.2
    ${REGISTRY}/rancher/mirrored-calico-cni:v3.20.2
    ${REGISTRY}/rancher/mirrored-calico-apiserver:v3.20.2
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-vsphere.txt
    ${REGISTRY}/rancher/mirrored-cloud-provider-vsphere-cpi-release-manager:v1.21.0
    ${REGISTRY}/rancher/mirrored-cloud-provider-vsphere-csi-release-driver:v2.3.0
    ${REGISTRY}/rancher/mirrored-cloud-provider-vsphere-csi-release-syncer:v2.3.0
    ${REGISTRY}/rancher/mirrored-k8scsi-csi-node-driver-registrar:v2.1.0
    ${REGISTRY}/rancher/mirrored-k8scsi-csi-resizer:v1.1.0
    ${REGISTRY}/rancher/mirrored-k8scsi-livenessprobe:v2.2.0
    ${REGISTRY}/rancher/mirrored-sig-storage-csi-attacher:v3.2.0
    ${REGISTRY}/rancher/mirrored-sig-storage-csi-provisioner:v2.2.0
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-multus.txt
    ${REGISTRY}/rancher/hardened-multus-cni:v3.7.1-build20211119
    ${REGISTRY}/rancher/hardened-cni-plugins:v0.9.1-build20211119
    ${REGISTRY}/rancher/hardened-sriov-network-operator:v1.0.0-build20210429
    ${REGISTRY}/rancher/hardened-sriov-network-config-daemon:v1.0.0-build20210429
    ${REGISTRY}/rancher/hardened-sriov-network-device-plugin:v3.3.1-build20210310
    ${REGISTRY}/rancher/hardened-sriov-cni:v2.6-build20210310
    ${REGISTRY}/rancher/hardened-ib-sriov-cni:v1.0.0-build20210310
    ${REGISTRY}/rancher/hardened-sriov-network-resources-injector:v1-build20210310
    ${REGISTRY}/rancher/hardened-sriov-network-webhook:v1.0.0-build20210429
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-harvester.txt
    ${REGISTRY}/rancher/harvester-cloud-provider:v0.1.1
    ${REGISTRY}/rancher/harvester-csi-driver:v0.1.1
    ${REGISTRY}/rancher/longhornio-csi-node-driver-registrar:v2.3.0
    ${REGISTRY}/rancher/longhornio-csi-resizer:v1.2.0
    ${REGISTRY}/rancher/longhornio-csi-provisioner:v2.1.2
    ${REGISTRY}/rancher/longhornio-csi-attacher:v3.2.1
EOF

# Continue to provide a legacy airgap archive set with the default CNI images
cat build/images-core.txt build/images-canal.txt > build/images.txt
